package edu.unf.cen6940.web;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import edu.unf.cen6940.dao.CategoryDAO;
import edu.unf.cen6940.dao.FacultyDAO;
import edu.unf.cen6940.dao.FacultyresearchDAO;
import edu.unf.cen6940.dao.FacultyresearchtostudentDAO;
import edu.unf.cen6940.dao.ResearchkeywordDAO;
import edu.unf.cen6940.dao.StudentDAO;

import edu.unf.cen6940.domain.Category;
import edu.unf.cen6940.domain.Faculty;
import edu.unf.cen6940.domain.Facultyresearch;
import edu.unf.cen6940.domain.Facultyresearchtostudent;
import edu.unf.cen6940.domain.Generatedproduct;
import edu.unf.cen6940.domain.Researchkeyword;
import edu.unf.cen6940.domain.Student;

import edu.unf.cen6940.service.FacultyresearchService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Facultyresearch entities
 * 
 */

@Controller("FacultyresearchController")
public class FacultyresearchController {

	/**
	 * DAO injected by Spring that manages Category entities
	 * 
	 */
	@Autowired
	private CategoryDAO categoryDAO;

	/**
	 * DAO injected by Spring that manages Faculty entities
	 * 
	 */
	@Autowired
	private FacultyDAO facultyDAO;

	/**
	 * DAO injected by Spring that manages Facultyresearch entities
	 * 
	 */
	@Autowired
	private FacultyresearchDAO facultyresearchDAO;

	/**
	 * DAO injected by Spring that manages Facultyresearchtostudent entities
	 * 
	 */
	@Autowired
	private FacultyresearchtostudentDAO facultyresearchtostudentDAO;

	/**
	 * DAO injected by Spring that manages Researchkeyword entities
	 * 
	 */
	@Autowired
	private ResearchkeywordDAO researchkeywordDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Facultyresearch entities
	 * 
	 */
	@Autowired
	private FacultyresearchService facultyresearchService;
	
	@Autowired
	private StudentDAO studentDAO;

	/**
	 * Save an existing Category entity
	 * 
	 */
	@RequestMapping("/saveFacultyresearchCategories")
	public ModelAndView saveFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId, @ModelAttribute Category categories) {
		Facultyresearch parent_facultyresearch = facultyresearchService.saveFacultyresearchCategories(facultyresearch_facultyResearchId, categories);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", parent_facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * Create a new Category entity
	 * 
	 */
	@RequestMapping("/newFacultyresearchCategories")
	public ModelAndView newFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("category", new Category());
		Set<Category> categorySet = categoryDAO.findAllCategorys();
		Map<Integer,String> categoryData = new HashMap<Integer, String>();
		for(Category category:categorySet){
			categoryData.put(category.getCategoryId(),category.getCategoryDescription());
		}
		mav.addObject("categoryList",categoryData);
		mav.addObject("newFlag", true);
		mav.setViewName("facultyresearch/categories/editCategories");

		return mav;
	}

	/**
	 * Delete an existing Facultyresearchtostudent entity
	 * 
	 */
	@RequestMapping("/deleteFacultyresearchFacultyresearchtostudents")
	public ModelAndView deleteFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_facultyresearchtostudents_facultyResearchId, @RequestParam Integer related_facultyresearchtostudents_studentId, @RequestParam Integer related_facultyresearchtostudents_facultyId) {
		ModelAndView mav = new ModelAndView();

		Facultyresearch facultyresearch = facultyresearchService.deleteFacultyresearchFacultyresearchtostudents(facultyresearch_facultyResearchId, related_facultyresearchtostudents_facultyResearchId, related_facultyresearchtostudents_studentId, related_facultyresearchtostudents_facultyId);

		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * Edit an existing Facultyresearchtostudent entity
	 * 
	 */
	@RequestMapping("/editFacultyresearchFacultyresearchtostudents")
	public ModelAndView editFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer facultyresearchtostudents_facultyResearchId, @RequestParam Integer facultyresearchtostudents_studentId, @RequestParam Integer facultyresearchtostudents_facultyId) {
		Facultyresearchtostudent facultyresearchtostudent = facultyresearchtostudentDAO.findFacultyresearchtostudentByPrimaryKey(facultyresearchtostudents_facultyResearchId, facultyresearchtostudents_studentId, facultyresearchtostudents_facultyId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearchtostudent", facultyresearchtostudent);
		mav.setViewName("facultyresearch/facultyresearchtostudents/editFacultyresearchtostudents");

		return mav;
	}

	/**
	 * Save an existing Faculty entity
	 * 
	 */
	@RequestMapping("/saveFacultyresearchFaculty")
	public ModelAndView saveFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId, @ModelAttribute Faculty faculty) {
		Facultyresearch parent_facultyresearch = facultyresearchService.saveFacultyresearchFaculty(facultyresearch_facultyResearchId, faculty);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", parent_facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * Edit an existing Category entity
	 * 
	 */
	@RequestMapping("/editFacultyresearchCategories")
	public ModelAndView editFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer categories_categoryId) {
		Category category = categoryDAO.findCategoryByPrimaryKey(categories_categoryId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("category", category);
		mav.setViewName("facultyresearch/categories/editCategories");

		return mav;
	}

	/**
	 * Delete an existing Category entity
	 * 
	 */
	@RequestMapping("/deleteFacultyresearchCategories")
	public ModelAndView deleteFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_categories_categoryId) {
		ModelAndView mav = new ModelAndView();

		Facultyresearch facultyresearch = facultyresearchService.deleteFacultyresearchCategories(facultyresearch_facultyResearchId, related_categories_categoryId);

		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * View an existing Facultyresearchtostudent entity
	 * 
	 */
	@RequestMapping("/selectFacultyresearchFacultyresearchtostudents")
	public ModelAndView selectFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer facultyresearchtostudents_facultyResearchId, @RequestParam Integer facultyresearchtostudents_studentId, @RequestParam Integer facultyresearchtostudents_facultyId) {
		Facultyresearchtostudent facultyresearchtostudent = facultyresearchtostudentDAO.findFacultyresearchtostudentByPrimaryKey(facultyresearchtostudents_facultyResearchId, facultyresearchtostudents_studentId, facultyresearchtostudents_facultyId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearchtostudent", facultyresearchtostudent);
		mav.setViewName("facultyresearch/facultyresearchtostudents/viewFacultyresearchtostudents");

		return mav;
	}

	/**
	 * Show all Category entities by Facultyresearch
	 * 
	 */
	@RequestMapping("/listFacultyresearchCategories")
	public ModelAndView listFacultyresearchCategories(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/categories/listCategories");

		return mav;
	}

	/**
	 * Delete an existing Researchkeyword entity
	 * 
	 */
	@RequestMapping("/deleteFacultyresearchResearchkeywords")
	public ModelAndView deleteFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_researchkeywords_researchKeywordId) {
		ModelAndView mav = new ModelAndView();

		Facultyresearch facultyresearch = facultyresearchService.deleteFacultyresearchResearchkeywords(facultyresearch_facultyResearchId, related_researchkeywords_researchKeywordId);

		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * Create a new Faculty entity
	 * 
	 */
	@RequestMapping("/newFacultyresearchFaculty")
	public ModelAndView newFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("faculty", new Faculty());
		mav.addObject("newFlag", true);
		mav.setViewName("facultyresearch/faculty/editFaculty");

		return mav;
	}

	/**
	 * Delete an existing Facultyresearch entity
	 * 
	 */
	@RequestMapping("/deleteFacultyresearch")
	public String deleteFacultyresearch(@RequestParam Integer facultyResearchIdKey) {
		Facultyresearch facultyresearch = facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey);
		facultyresearchService.deleteFacultyresearch(facultyresearch);
		return "forward:/indexFacultyresearch";
	}

	/**
	 * Create a new Facultyresearchtostudent entity
	 * 
	 */
	@RequestMapping("/newFacultyresearchFacultyresearchtostudents")
	public ModelAndView newFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearchtostudent", new Facultyresearchtostudent());
		mav.addObject("newFlag", true);
		Set<Student> studentSet = studentDAO.findAllStudents();
		Map<Integer,String> studentData = new HashMap<Integer, String>();
		for(Student student:studentSet){
			studentData.put(student.getStudentId(),student.getLastName()+"| "+student.getFirstName());
		}
		mav.addObject("studentList",studentData);
		Set<Faculty> facultySet = facultyDAO.findAllFacultys();
		Map<Integer,String> categoryData = new HashMap<Integer, String>();
		for(Faculty faculty:facultySet){
			categoryData.put(faculty.getFacultyId(),faculty.getLastName()+"| "+faculty.getFirstName());
		}
		mav.addObject("facultyList",categoryData);
		mav.addObject("facultyId", facultyresearchDAO.findFacultyresearchByFacultyResearchId(facultyresearch_facultyResearchId).getFaculty().getFacultyId());

		mav.setViewName("facultyresearch/facultyresearchtostudents/editFacultyresearchtostudents");

		return mav;
	}

	/**
	 * Select the child Faculty entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteFacultyresearchFaculty")
	public ModelAndView confirmDeleteFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_faculty_facultyId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("faculty", facultyDAO.findFacultyByPrimaryKey(related_faculty_facultyId));
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.setViewName("facultyresearch/faculty/deleteFaculty");

		return mav;
	}

	/**
	 * View an existing Category entity
	 * 
	 */
	@RequestMapping("/selectFacultyresearchCategories")
	public ModelAndView selectFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer categories_categoryId) {
		Category category = categoryDAO.findCategoryByPrimaryKey(categories_categoryId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("category", category);
		mav.setViewName("facultyresearch/categories/viewCategories");

		return mav;
	}

	/**
	 * Edit an existing Facultyresearch entity
	 * 
	 */
	@RequestMapping("/editFacultyresearch")
	public ModelAndView editFacultyresearch(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.addObject("facultyId", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey).getFaculty().getFacultyId());
		mav.addObject("facultyName", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey).getFaculty().getFirstName()+" "+facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey).getFaculty().getLastName());
		Set<Faculty> facultySet = facultyDAO.findAllFacultys();
		Map<Integer,String> facultyData = new HashMap<Integer, String>();
		for(Faculty faculty:facultySet){
			facultyData.put(faculty.getFacultyId(),faculty.getFirstName()+" "+faculty.getLastName());
		}
		mav.addObject("facultyList",facultyData);
		mav.setViewName("facultyresearch/editFacultyresearch");

		return mav;
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Edit an existing Faculty entity
	 * 
	 */
	@RequestMapping("/editFacultyresearchFaculty")
	public ModelAndView editFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer faculty_facultyId) {
		Faculty faculty = facultyDAO.findFacultyByPrimaryKey(faculty_facultyId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("faculty", faculty);
		mav.setViewName("facultyresearch/faculty/editFaculty");

		return mav;
	}

	/**
	 * Show all Faculty entities by Facultyresearch
	 * 
	 */
	@RequestMapping("/listFacultyresearchFaculty")
	public ModelAndView listFacultyresearchFaculty(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/faculty/listFaculty");

		return mav;
	}

	/**
	 * Select the child Researchkeyword entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteFacultyresearchResearchkeywords")
	public ModelAndView confirmDeleteFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_researchkeywords_researchKeywordId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("researchkeyword", researchkeywordDAO.findResearchkeywordByPrimaryKey(related_researchkeywords_researchKeywordId));
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.setViewName("facultyresearch/researchkeywords/deleteResearchkeywords");

		return mav;
	}

	/**
	 * View an existing Faculty entity
	 * 
	 */
	@RequestMapping("/selectFacultyresearchFaculty")
	public ModelAndView selectFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer faculty_facultyId) {
		Faculty faculty = facultyDAO.findFacultyByPrimaryKey(faculty_facultyId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("faculty", faculty);
		mav.setViewName("facultyresearch/faculty/viewFaculty");

		return mav;
	}

	/**
	 * Show all Facultyresearchtostudent entities by Facultyresearch
	 * 
	 */
	@RequestMapping("/listFacultyresearchFacultyresearchtostudents")
	public ModelAndView listFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/facultyresearchtostudents/listFacultyresearchtostudents");

		return mav;
	}

	/**
	 * Show all Researchkeyword entities by Facultyresearch
	 * 
	 */
	@RequestMapping("/listFacultyresearchResearchkeywords")
	public ModelAndView listFacultyresearchResearchkeywords(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/researchkeywords/listResearchkeywords");

		return mav;
	}

	/**
	 * Edit an existing Researchkeyword entity
	 * 
	 */
	@RequestMapping("/editFacultyresearchResearchkeywords")
	public ModelAndView editFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer researchkeywords_researchKeywordId) {
		Researchkeyword researchkeyword = researchkeywordDAO.findResearchkeywordByPrimaryKey(researchkeywords_researchKeywordId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("researchkeyword", researchkeyword);
		mav.setViewName("facultyresearch/researchkeywords/editResearchkeywords");

		return mav;
	}

	/**
	 * Show all Facultyresearch entities
	 * 
	 */
	@RequestMapping("/indexFacultyresearch")
	public ModelAndView listFacultyresearchs() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearchs", facultyresearchService.loadFacultyresearchs());

		mav.setViewName("facultyresearch/listFacultyresearchs");

		return mav;
	}

	
	/**
	 * Select the child Facultyresearchtostudent entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteFacultyresearchFacultyresearchtostudents")
	public ModelAndView confirmDeleteFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_facultyresearchtostudents_facultyResearchId, @RequestParam Integer related_facultyresearchtostudents_studentId, @RequestParam Integer related_facultyresearchtostudents_facultyId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearchtostudent", facultyresearchtostudentDAO.findFacultyresearchtostudentByPrimaryKey(related_facultyresearchtostudents_facultyResearchId, related_facultyresearchtostudents_studentId, related_facultyresearchtostudents_facultyId));
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.setViewName("facultyresearch/facultyresearchtostudents/deleteFacultyresearchtostudents");

		return mav;
	}

	/**
	 * Select the Facultyresearch entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteFacultyresearch")
	public ModelAndView confirmDeleteFacultyresearch(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/deleteFacultyresearch");

		return mav;
	}

	/**
	 * Entry point to show all Facultyresearch entities
	 * 
	 */
	public String indexFacultyresearch() {
		return "redirect:/indexFacultyresearch";
	}

	/**
	 */
	@RequestMapping("/facultyresearchController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * Select the child Category entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteFacultyresearchCategories")
	public ModelAndView confirmDeleteFacultyresearchCategories(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_categories_categoryId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("category", categoryDAO.findCategoryByPrimaryKey(related_categories_categoryId));
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.setViewName("facultyresearch/categories/deleteCategories");

		return mav;
	}

	/**
	 * Create a new Researchkeyword entity
	 * 
	 */
	@RequestMapping("/newFacultyresearchResearchkeywords")
	public ModelAndView newFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("researchkeyword", new Researchkeyword());
		mav.addObject("newFlag", true);
		Set<Researchkeyword> researchkeywordSet = researchkeywordDAO.findAllResearchkeywords();
		Map<Integer,String> researchkeywordData = new HashMap<Integer, String>();
		for(Researchkeyword researchkeyword:researchkeywordSet){
			researchkeywordData.put(researchkeyword.getResearchKeywordId(),researchkeyword.getKeyword());
		}
		mav.addObject("reesearchkeywordList",researchkeywordData);
		mav.setViewName("facultyresearch/researchkeywords/editResearchkeywords");

		return mav;
	}

	/**
	 * Save an existing Facultyresearch entity
	 * 
	 */
	@RequestMapping("/saveFacultyresearch")
	public String saveFacultyresearch(@ModelAttribute Facultyresearch facultyresearch) {
		facultyresearchService.saveFacultyresearch(facultyresearch);
		return "forward:/indexFacultyresearch";
	}

	/**
	 * Select an existing Facultyresearch entity
	 * 
	 */
	@RequestMapping("/selectFacultyresearch")
	public ModelAndView selectFacultyresearch(@RequestParam Integer facultyResearchIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", facultyresearchDAO.findFacultyresearchByPrimaryKey(facultyResearchIdKey));
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}
	

	/**
	 * Delete an existing Faculty entity
	 * 
	 */
	@RequestMapping("/deleteFacultyresearchFaculty")
	public ModelAndView deleteFacultyresearchFaculty(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer related_faculty_facultyId) {
		ModelAndView mav = new ModelAndView();

		Facultyresearch facultyresearch = facultyresearchService.deleteFacultyresearchFaculty(facultyresearch_facultyResearchId, related_faculty_facultyId);

		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * Create a new Facultyresearch entity
	 * 
	 */
	@RequestMapping("/newFacultyresearch")
	public ModelAndView newFacultyresearch() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("facultyresearch", new Facultyresearch());
		mav.addObject("newFlag", true);
		
		Set<Faculty> facultySet = facultyDAO.findAllFacultys();
		Map<Integer,String> facultyData = new HashMap<Integer, String>();
		for(Faculty faculty:facultySet){
			facultyData.put(faculty.getFacultyId(),faculty.getFirstName()+" "+faculty.getLastName());
		}
		mav.addObject("facultyList",facultyData);
		
		/*Set<Faculty> facultySet = facultyDAO.findAllFacultys();
		Map<Integer,String> facultyData = new HashMap<Integer, String>();
		for(Faculty faculty:facultySet){
			facultyData.put(faculty.getFacultyId(),faculty.getLastName()+"| "+faculty.getFirstName());
		}
		mav.addObject("facultyList",facultyData);*/
		mav.setViewName("facultyresearch/editFacultyresearch");

		return mav;
	}

	/**
	 * Save an existing Facultyresearchtostudent entity
	 * 
	 */
	@RequestMapping("/saveFacultyresearchFacultyresearchtostudents")
	public String saveFacultyresearchFacultyresearchtostudents(@RequestParam Integer facultyresearch_facultyResearchId, @ModelAttribute Facultyresearchtostudent facultyresearchtostudents) {
		Facultyresearch parent_facultyresearch = facultyresearchService.saveFacultyresearchFacultyresearchtostudents(facultyresearch_facultyResearchId, facultyresearchtostudents);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", parent_facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return "redirect:selectFacultyresearch?facultyResearchIdKey=" + facultyresearch_facultyResearchId.toString() + "&";
	}

	/**
	 * Save an existing Researchkeyword entity
	 * 
	 */
	@RequestMapping("/saveFacultyresearchResearchkeywords")
	public ModelAndView saveFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId, @ModelAttribute Researchkeyword researchkeywords) {
		Facultyresearch parent_facultyresearch = facultyresearchService.saveFacultyresearchResearchkeywords(facultyresearch_facultyResearchId, researchkeywords);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("facultyresearch", parent_facultyresearch);
		mav.setViewName("facultyresearch/viewFacultyresearch");

		return mav;
	}

	/**
	 * View an existing Researchkeyword entity
	 * 
	 */
	@RequestMapping("/selectFacultyresearchResearchkeywords")
	public ModelAndView selectFacultyresearchResearchkeywords(@RequestParam Integer facultyresearch_facultyResearchId, @RequestParam Integer researchkeywords_researchKeywordId) {
		Researchkeyword researchkeyword = researchkeywordDAO.findResearchkeywordByPrimaryKey(researchkeywords_researchKeywordId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("facultyresearch_facultyResearchId", facultyresearch_facultyResearchId);
		mav.addObject("researchkeyword", researchkeyword);
		mav.setViewName("facultyresearch/researchkeywords/viewResearchkeywords");

		return mav;
	}
	
	@RequestMapping("/searchFacultyresearch")
	public String searchFacultyresearch(@RequestParam String searchTerm, Model model){
		model.addAttribute("facultyresearchs",facultyresearchDAO.searchByTerm(searchTerm));
		model.addAttribute("searchTerm", searchTerm);
		return "facultyresearch/listFacultyresearchs";
	}
	
	@RequestMapping("/searchFacultyresearchByFacultyId")
	public String searchFacultyresearchByFacultyId(@RequestParam int id, Model model){
		model.addAttribute("facultyresearchs",facultyresearchDAO.searchFacultyresearchByFacultyId(id));
		return "facultyresearch/listFacultyresearchs";
	}
	
	@RequestMapping("/searchFacultyresearchByStudentId")
	public String searchFacultyresearchByStudentId(@RequestParam int id, Model model){
		model.addAttribute("facultyresearchs",facultyresearchDAO.searchFacultyresearchByStudentId(id));
		return "facultyresearch/listFacultyresearchs";
	}
	
	@RequestMapping("/searchFacultyresearchByStatus")
	public String searchFacultyresearchByStatusId(@RequestParam String status, Model model){
		model.addAttribute("facultyresearchs",facultyresearchDAO.searchFacultyresearchByStatus(status));
		return "facultyresearch/listFacultyresearchs";
	}
}